#include "EnergyBand.h"

const string EB::biassymbol = "Bias";
const string EB::eigvaluesymbol = "Eigenvalues";

void EB::getEnergyBands(int id)
{
	// The functor constructed and options are pulled from expression!
	EnergyBands enBands = getWithParameters();
	
	MLPutValue(stdlink,enBands(id).bands);
}
	
EnergyBands EB::getWithParameters()
{
	// The resulting functor is allocated!
	EnergyBands enBands;
		
	// The options are supplied.
	rule::list opts;
	if(!MLGetValue(stdlink,&opts))
		return enBands;

	// Now we set the options!
	const size_t rulesize = opts.size();
	for(size_t r = 0; r < rulesize; r++)
	{
		// Rules from Mathematica always have symbols first.
		if(!opts[r].first.isSymbolType())
			continue;
		
		// The variable is pulled out.
		symbol sym = opts[r].first.toSymbol();
		variant var = opts[r].second;
		
		if(sym.name() == biassymbol)
		{
			if(var.isNumericType())
				enBands.bias = var.toDouble();
		}
		else if(sym.name() == eigvaluesymbol)
		{
			if(var.isNumericType())
			{
				enBands.eig_val = EnergyBands::count;
				enBands.N_eig = var.toNumeric();
			}
			else if(var.isNumericListType() || var.isRangeType())
			{
				enBands.eig_val = EnergyBands::interval;
				enBands.eig_min = var.toRange().begin;
				enBands.eig_max = var.toRange().end;
			}
		}
	}

	return enBands;
}